//:C07:UnionClass.cpp
// Union with constructors and member functions
#include <ios>
#include <iostream>
using namespace std;

union U{
    private:    // Access control too!
        int i;
        float f;
    public:
        U(int a);
        U(float b);
        ~U();
        int read_int();
        float read_float();    
};

U::U(int a){
    i = a;
}

U::U(float b){
    f = b;
}

U::~U(){
    cout << "U::~U()\n";
}

int U::read_int(){
    return i;
}

float U::read_float(){
    return f;
}

int main(void){
    U X(12), Y(1.9f);
    cout << X.read_int() << '\n';
    cout << Y.read_float() << '\n';
    return 0;
}